#pragma once
/****************************************
*多线程模型：采用Actor模型的Theron库封装
*功能：
*	1.支持线程间与线程内不同数据类型的通
*	信；
*   2.支持线程内定时任务;
****************************************/

#include <Theron/Theron.h>
#include "singleton.h"
//#include <TImer/Timer.h>
#include <string>
#include <vector>
#include <list>
#include <map>
#include "DataCenter.h"
#include "Timer.h"

typedef vector<void*> ArgumentV;

enum {
	THREAD_ADDRESS = 0,
	PARAM_ONE,
};
typedef map<int, void*> ArgumentM;   //in this case,we save two params(a thread_addr and an other param) in ArgumentM,the two key is 'THREAD_ADDRESS'
									//and 'PARAM_ONE'
									//usually,if we has a thread_addr and n params(totally n+1),we should has a enum that is bellow
									// enum{
									//    THREAD_ADDRESS = 0,
									//    PARAM_ONE,
									//    PARAM_TWO,
									//    ...
									//    PARAM_N,
									//    };

enum {
	TIME_ID_ONE = 0,
	TIME_ID_TWO,
	TIME_TOTAL,
};

//定时器单元参数
struct time_param {
	int time_id;
};

//class CThreadA : public Theron::Actor,public Singleton<CThreadA>
class CThreadA : public Theron::Actor
{
public:
	typedef  void(CThreadA::*CALLBACK_FN)(void *);
	int m_id;
	Theron::Framework t_framwork;

	friend class Singleton<CThreadA>;
	CThreadA() : Theron::Actor(t_framwork) {

	}
	explicit CThreadA(Theron::Framework &framwork) :Theron::Actor(framwork)
	{
		//注册消息函数
		RegisterHandler(this, &CThreadA::handleInt);
		RegisterHandler(this, &CThreadA::handleString);
	}

	int setID(int id);
	int getID();
	void start();

	void setTimer(int millisecond, int timeid);
	void cancelTimer(int timeid);
	void static onTimer(void *args);

	void handleInt(const int& item, const Theron::Address from);
	void handleString(const std::string& data, const Theron::Address from);
	int send2ThreadbyID(int data, int ID);


public:
	//    Timer* t1;
	//    Timer* t2;
	//    int id1;
	//    int id2;
private:
	map<int, Timer*> m_timer_map;
	map<int, string> m_timerid_map;  //to save timeid in string permanently

	map<int, int> int_timerid_map;   //to save timeid in int permanently,so it can be use in ArgumentM
	map<int, ArgumentM> m_timeargs_map; // a timeid relate a map of argumemts(ArgumentV),so it can be use in onTimer()
};
